#include <chrono>
#include <geometry_msgs/msg/twist.hpp>
#include <random>
#include <rclcpp/rclcpp.hpp>

class TurtleControl : public rclcpp::Node
{
private:
    /* data */
    rclcpp::TimerBase::SharedPtr _timer;
    rclcpp::Publisher<geometry_msgs::msg::Twist>::SharedPtr _publisher;

    void _timer_callback()
    {
        auto msg = geometry_msgs::msg::Twist();
        std::mt19937 gen(std::random_device{}());
        std::uniform_real_distribution<double> dis(-3.0, 3.0);

        msg.angular.z = dis(gen);
        msg.linear.x = dis(gen);
        msg.linear.y = dis(gen);
        RCLCPP_INFO(this->get_logger(),
                    "linear{x: %f,y: %f,z: %f}, angular{x: %f,y: %f,z: %f}",
                    msg.linear.x, msg.linear.y, msg.linear.z, msg.angular.x,
                    msg.angular.y, msg.angular.z);
        _publisher->publish(msg);
    }

public:
    TurtleControl(const std::string &node_name) : rclcpp::Node(node_name)
    {
        _publisher =
            create_publisher<geometry_msgs::msg::Twist>("/turtle1/cmd_vel", 10);
        using namespace std::chrono_literals;
        _timer = create_wall_timer(
            1s, std::bind(&TurtleControl::_timer_callback, this));
    }
    ~TurtleControl() {}
};

int main(int argc, char **argv)
{
    rclcpp::init(argc, argv);
    auto node = std::make_shared<TurtleControl>("turtle_control");
    rclcpp::spin(node);
    rclcpp::shutdown();
    return 0;
}